package com.ge.boot11actuator.controller;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.MeterRegistry;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {

    private final Counter counter;

    public HelloController(MeterRegistry meterRegistry) {
        // 提供一个名为MyHelloController的计数器
        this.counter = meterRegistry.counter("MyHelloCounter");
    }

    @GetMapping("/hello")
    public String hello() {
        // 每次方法被调用，即请求路径被访问时，进行计数
        counter.increment();
        return "hello";
    }
}
